home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / prefIcq.js < prev    next >
Encoding:
Text File  |  2002-06-25  |  46.6 KB  |  1,596 lines

  1. var IMServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  2. var pIIMManager  = IMServiceClass.getService(Components.interfaces.nsIIMManager)
  3. var lastRadio = null;
  4. var lastViewRadio = null;
  5. var allEnums = Components.interfaces.nsAimPrivacyModes;
  6. var stateEnums = Components.interfaces.nsAimOnlineStates;
  7. var globalPrivacyObject = pIIMManager.QueryInterface(Components.interfaces.nsIAimPrivacy);
  8. var MozPreferences = Components.classes['@mozilla.org/preferences-service;1'];
  9. MozPreferences = MozPreferences.getService();
  10. MozPreferences = MozPreferences.QueryInterface(Components.interfaces.nsIPrefBranch);
  11.  
  12.  
  13. //connection panel
  14. var connLinks = new Object();
  15. connLinks.ConnectionName = "";
  16. connLinks.SessionType    = "";
  17. connLinks.Host           = "";
  18. connLinks.Port           = "";
  19. connLinks.ProxyHost      = "";
  20. connLinks.ProxyPort      = "";
  21. connLinks.ProxyUser      = "";
  22. connLinks.ProxyPassword  = "";
  23. connLinks.ProxyProtocol  = "";
  24. connLinks.IsProxy        = false;
  25. connLinks.ConnectionType = 0;
  26.  
  27. //end connection panel
  28.  
  29.  
  30. function getString(name)
  31. {
  32.     if (aimStringBundle())
  33.                 return aimStringBundle().GetStringFromName(name);
  34.         else    
  35.         return "";
  36. }
  37.  
  38. function EditAwayMessageOnLoad()
  39. {
  40.     var nameItem = document.getElementById("awayMessageName");
  41.     var textItem = document.getElementById("awayMessageText");
  42.  
  43.     nameItem.value = window.arguments[1];
  44.     textItem.value = window.arguments[2];
  45.     nameItem.focus();
  46.  
  47.  
  48.     // set the OK, Cancel callbacks
  49.  
  50.     if ( nameItem.value == "" ) 
  51.         doSetOKCancel(AddAwayMessageOnOK, 0);
  52.     else    
  53.         doSetOKCancel(EditAwayMessageOnOK, 0);
  54. }
  55.  
  56. function PrefIcqAwayOnLoad()
  57. {
  58.   if( (false == IsSignedOn()) || (false == isIcq())) {
  59.       DisableIcqAwayUI();
  60.         aimErrorBox(aimString("icqaway.entermsg"));
  61.     parent.hPrefWindow.registerOKCallbackFunc( DiscardAwayChanges );
  62.       }
  63. }
  64.  
  65. function PrefIcqStyleOnload()
  66. {
  67.   var textData = document.getElementById("textColorData");
  68.   var backgroundData = document.getElementById("backgroundColorData");
  69.   var customTextColor = textData.getAttribute("value");
  70.   var customBackgroundColor = backgroundData.getAttribute("value");
  71.  
  72.   if ( !customBackgroundColor || customBackgroundColor == "")
  73.     customBackgroundColor = "#FFFFFF";
  74.   if ( !customTextColor || customTextColor == "")
  75.     customTextColor = "#000000";
  76.   setColorWell("textCW", customTextColor);
  77.   setColorWell("backgroundCW", customBackgroundColor);
  78.  
  79.   textData.setAttribute("value", customTextColor); 
  80.   backgroundData.setAttribute("value", customBackgroundColor); 
  81.  
  82.   SwapSpecialStyles();
  83. }
  84.  
  85. function SwapSpecialStyles()
  86. {
  87.   if (document.getElementById("textstyles").getAttribute("value") == "1")
  88.   {
  89.     document.getElementById("bold").setAttribute("disabled", "false");
  90.     document.getElementById("italics").setAttribute("disabled", "false");
  91.     document.getElementById("underline").setAttribute("disabled", "false");
  92.   }
  93.   else
  94.   {
  95.     document.getElementById("bold").setAttribute("disabled","true");
  96.     document.getElementById("italics").setAttribute("disabled", "true");
  97.     document.getElementById("underline").setAttribute("disabled", "true");
  98.   }
  99. }
  100.  
  101. function GetColorAndUpdate(ColorWellID)
  102. {
  103.   var colorObj = new Object;
  104.   var colorWell = document.getElementById(ColorWellID);
  105.   var customTextColor = document.getElementById("textColorData").getAttribute("value"); 
  106.   var customBackgroundColor = document.getElementById("backgroundColorData").getAttribute("value"); 
  107.   if (!colorWell) return;
  108.  
  109.   colorObj.NoDefault = true;
  110.  
  111.   switch( ColorWellID )
  112.   {
  113.     case "textCW":
  114.       colorObj.Type = "Text";
  115.       colorObj.TextColor = customTextColor;
  116.       break;
  117.     case "backgroundCW":
  118.       colorObj.Type = "Page";
  119.       colorObj.PageColor = customBackgroundColor;
  120.       break;
  121.   }
  122.  
  123.   window.openDialog("chrome://editor/content/EdColorPicker.xul", "_blank", "chrome,close,titlebar,modal", "", colorObj);
  124.  
  125.   if (colorObj.Cancel)
  126.     return;
  127.  
  128.   var color = "";
  129.   switch( ColorWellID )
  130.   {
  131.     case "textCW":
  132.       color = customTextColor = colorObj.TextColor;
  133.       document.getElementById("textColorData").setAttribute("value", color); 
  134.       break;
  135.     case "backgroundCW":
  136.       color = customBackgroundColor = colorObj.BackgroundColor;
  137.       document.getElementById("backgroundColorData").setAttribute("value", color);
  138.       break;
  139.   }
  140.   setColorWell(ColorWellID, color); 
  141. }
  142.  
  143.  
  144. function GetUserAdd()
  145. {
  146.   var fldUserName = top.document.getElementById("fldUserName");
  147.     var pIAimPrivacy = aimPrivacy();
  148.   var name = fldUserName.value;
  149.   if ( name && name != "" ) {
  150.         if ( top.addMode == "Allow" ) {
  151.             pIAimPrivacy.AllowListAdd( name );
  152.         }
  153.         else if ( top.addMode == "Deny" ) {
  154.             pIAimPrivacy.DenyListAdd( name );
  155.         }
  156.         top.opener.updateListBoxSelection(top.addMode);
  157.         top.window.close();
  158.  }
  159. }
  160.  
  161. function updateListBoxSelection(mode){
  162.    var targetListBox = document.getElementById(mode);
  163.    var targetListBoxSelectedCount = targetListBox.selectedCount
  164.    var targetListBoxRows = targetListBox.listBoxObject.getRowCount();
  165.    if(targetListBoxRows >0 && targetListBoxSelectedCount <1){
  166.       targetListBox.selectedIndex=0;
  167.    }
  168. }
  169.  
  170.  
  171.  
  172. function StandardURL(s) {
  173.     var clazz = Components.classes["@mozilla.org/network/standard-url;1"];
  174.     var iface = Components.interfaces.nsIURL;
  175.     var obj = clazz.createInstance(iface);
  176.     obj.spec = s;
  177.     return obj;
  178.  
  179.  
  180. function Sound() {
  181.     var clazz = Components.classes["@mozilla.org/sound;1"];
  182.     var iface = Components.interfaces.nsISound;
  183.     var obj = clazz.createInstance(iface);
  184.     return obj;
  185. }
  186.  
  187. function PlaySound( myURIPref )
  188. {
  189.     var sound = new Sound();
  190.     var myURI;
  191.  
  192.     try {
  193.         myURI = aimPrefsManager().GetCharPref( myURIPref , null, false );
  194.     }
  195.     catch(e) {
  196.         try {
  197.             myURI = aimPrefsManager().GetCharPref( myURIPref , null, true); // get the global one if the per screen name doesnt work
  198.   }
  199.         catch(e) {
  200.             return;
  201.         }         
  202.     }        
  203.  
  204.     var uri = new StandardURL(myURI);
  205.     if ( sound != undefined && sound != null && uri != undefined && uri != null ) {
  206.         try {
  207.             sound.play( uri );
  208.         }
  209.         catch( e ) {
  210.             // device may not support sound, so ignore
  211.         }
  212.     }    
  213. }
  214.  
  215. /* away messages */
  216.  
  217. var datasource = null;
  218. var RDF = null;
  219. var awayMessages = null;
  220.  
  221. function
  222. GetRDFService()
  223. {
  224.     if ( RDF == null ) {
  225.         RDF=aimRDF();
  226.     }
  227. }
  228.  
  229. function
  230. RemoveTarget( msgName )
  231. {
  232.     GetRDFService();
  233.  
  234.     var messages_file = GetRdfFileUrl("default-messages-icq.rdf", "icqdm.rdf");  
  235.     var datasource = RDF.GetDataSource(messages_file);
  236.  
  237.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  238.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  239.       container.Init(datasource, RDF.GetResource("NC:ICQ/AwayMessageBag"));
  240.  
  241.     var elements = container.GetElements();
  242.     var target, node;
  243.     var nameResource = 
  244.                 RDF.GetResource("http://home.netscape.com/NC-rdf#MsgName");
  245.     while ( elements.hasMoreElements() ) {
  246.         node = elements.getNext();
  247.         if ( node ) 
  248.             target = datasource.GetTarget( node, nameResource, 
  249.                 true );
  250.         if ( target ) 
  251.             target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
  252.         if ( target && target.Value == msgName ) {
  253.             container.RemoveElement( node, true );
  254.             datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  255.         }
  256.     }
  257.     return null;
  258. }
  259.  
  260. function
  261. SetAwayMessageTarget( msgName, msgText )
  262. {
  263.     GetRDFService();
  264.  
  265.     var messages_file = GetRdfFileUrl("default-messages-icq.rdf", "icqdm.rdf");  
  266.     var datasource = RDF.GetDataSource(messages_file);
  267.  
  268.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  269.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  270.       container.Init(datasource, RDF.GetResource("NC:ICQ/AwayMessageBag"));
  271.  
  272.     var elements = container.GetElements();
  273.     var nametarget, texttarget, node;
  274.     var nameResource = 
  275.                 RDF.GetResource("http://home.netscape.com/NC-rdf#MsgName");
  276.     var textResource = 
  277.                 RDF.GetResource("http://home.netscape.com/NC-rdf#MsgText");
  278.     while ( elements.hasMoreElements() ) {
  279.         node = elements.getNext();
  280.         if ( node ) 
  281.             nametarget = datasource.GetTarget( node, nameResource, 
  282.                 true );
  283.         if ( nametarget ) 
  284.             nametarget = nametarget.QueryInterface(Components.interfaces.nsIRDFLiteral);
  285.         if ( nametarget && nametarget.Value == msgName ) {
  286.             texttarget = datasource.GetTarget( node, textResource, 
  287.                 true );
  288.             if ( texttarget ) 
  289.                 texttarget = texttarget.QueryInterface(Components.interfaces.nsIRDFLiteral);
  290.             if ( texttarget ) {
  291.                 var newText = RDF.GetLiteral(msgText);
  292.                 datasource.Change( node, textResource,
  293.                     texttarget, newText);
  294.                 datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  295.             }
  296.             break;
  297.         }
  298.     }
  299. }
  300.  
  301. function modeToRadio(mode)
  302. {
  303.  
  304.     switch(mode) {
  305.     case allEnums.AllowAll:
  306.     dump ("allEnums.AllowAll\n" );
  307.         return document.getElementById("icq_privacy_contact_allowallusers"); 
  308.         break;
  309.     case allEnums.AllowBuddies:
  310.     dump ("allEnums.AllowBuddies\n" );
  311.         return document.getElementById("icq_privacy_contact_allowbuddylistusers"); 
  312.         break;
  313.     case allEnums.AllowList:
  314.     dump ("allEnums.AllowOnlyList\n" );
  315.         return document.getElementById("icq_privacy_contact_allowonlylist"); 
  316.         break;
  317.     case allEnums.DenyAll:
  318.     dump ("allEnums.DenyAll\n" );
  319.       
  320.         return document.getElementById("icq_privacy_contact_blockallusers"); 
  321.         break;
  322.     case allEnums.DenyList:
  323.     dump ("allEnums.DenyList\n" );
  324.         return document.getElementById("icq_privacy_contact_blocklistusers"); 
  325.         break;
  326.     default:
  327.         dump("Bad privacy mode\n");
  328.         return document.getElementById("icq_privacy_contact_allowallusers"); 
  329.         break;
  330.     }
  331. }
  332.  
  333. function privacyModeRadio(mode)
  334. {
  335.   lastRadio.checked = false;
  336.   lastRadio = modeToRadio(mode);
  337.   lastRadio.checked = true;
  338.   parent.lastPrivacyMode = mode;
  339. }
  340.  
  341. /*
  342. function viewToRadio(view)
  343. {
  344.     switch(view) {
  345.     case '1':
  346.         return document.getElementById("nodisclosure"); 
  347.         break;
  348.     case '2':
  349.         return document.getElementById("limiteddisclosure"); 
  350.         break;
  351.     case '3':
  352.         return document.getElementById("fulldisclosure"); 
  353.         break;
  354.     default:
  355.         dump("Bad privacy view\n");
  356.         return document.getElementById("nodisclosure"); 
  357.         break;
  358.     }
  359. }
  360.  
  361. function privacyViewRadio(view)
  362. {
  363.   parent.lastPrivacyView = view;
  364. }
  365. */
  366. AdminCallback = new Object();
  367. AdminCallback.OnRequestInfoComplete = function(type,info)
  368. {
  369.     switch (type) { 
  370.     case Components.interfaces.nsIAimAdminInfo.RegistrationStatusPreference:
  371.         parent.lastPrivacyView = info;
  372.         lastViewRadio = viewToRadio(parent.lastPrivacyView);
  373.     
  374.         if ( lastViewRadio != undefined && lastViewRadio != null) {
  375.             var privacyViewElement = document.getElementById("privacyView");
  376.             privacyViewElement.selectedItem = lastViewRadio;
  377.         }
  378.         break;
  379.     default:
  380.         break;
  381.     }
  382. }
  383. AdminCallback.OnRequestInfoError = function(pErrMsg)
  384. {
  385.     dump("OnRequestInfoError\n");
  386. }
  387.  
  388. adminGetterCallback = new Object();
  389.  
  390. adminGetterCallback.ExecuteIfReady = function()
  391. {
  392.     aimAdminManager().RequestInfoRegistrationStatusPreference(AdminCallback);
  393. }
  394.  
  395.  
  396. function DisablePrivacyUI()
  397. {
  398.         var el = document.getElementById("icq_privacy_contact_allowallusers");
  399.         if ( el )
  400.             el.setAttribute( "disabled", "true" );
  401.         el = document.getElementById("icq_privacy_contact_allowbuddylistusers");
  402.         if ( el )
  403.             el.setAttribute( "disabled", "true" );
  404.         el = document.getElementById("icq_privacy_contact_allowonlylist");
  405.         if ( el )
  406.             el.setAttribute( "disabled", "true" );
  407.         el = document.getElementById("icq_privacy_contact_blockallusers");
  408.         if ( el )
  409.             el.setAttribute( "disabled", "true" );
  410.         el = document.getElementById("icq_privacy_contact_blocklistusers");
  411.         if ( el )
  412.             el.setAttribute( "disabled", "true" );
  413.         el = document.getElementById("button1");
  414.         if ( el )
  415.             el.setAttribute( "disabled", "true" );
  416.         el = document.getElementById("button2");
  417.         if ( el )
  418.             el.setAttribute( "disabled", "true" );
  419.         el = document.getElementById("button3");
  420.         if ( el )
  421.             el.setAttribute( "disabled", "true" );
  422.         el = document.getElementById("button4");
  423.         if ( el )
  424.             el.setAttribute( "disabled", "true" );
  425.         el = document.getElementById("authMode");
  426.         if ( el )
  427.             el.setAttribute( "disabled", "true" );
  428.         el = document.getElementById("onlineStatus");
  429.     if ( el )
  430.             el.setAttribute( "disabled", "true" );
  431.   
  432.         el = document.getElementById("icq_privacy_authorization_required");
  433.         if ( el )
  434.             el.setAttribute( "disabled", "true" );
  435.         el = document.getElementById("icq_privacy_authorization_no");
  436.     if ( el )
  437.             el.setAttribute( "disabled", "true" );
  438. }
  439.  
  440. function DiscardPrivacyChanges()
  441. {
  442.     aimErrorBox(aimString("icqprivacy.exitmsg"));
  443. }
  444.  
  445. function IsSignedOn()
  446. {
  447.     var state = aimSession().CurrentState;
  448. dump( "state is " + state + " \n" );
  449.  
  450.     if ( state == stateEnums.Online || state == stateEnums.OnlineAway )
  451.         return true;
  452.     return false;
  453. }
  454.  
  455. function PrefIcqPrivacyOnLoad()
  456. {
  457.   if( (false == IsSignedOn()) || (isIcq() == false) ) {
  458.       DisablePrivacyUI();
  459.         aimErrorBox(aimString("icqprivacy.entermsg"));
  460.         parent.hPrefWindow.registerOKCallbackFunc( DiscardPrivacyChanges );
  461.     }
  462.     else {
  463.         parent.hPrefWindow.registerOKCallbackFunc( AssertPrivacyChanges );
  464.     var pAimPrefs =  pIIMManager.QueryInterface(Components.interfaces.nsIPrefsManager);
  465.  
  466.       //if (document.documentElement.getAttribute("isIcqPanel") != "true") 
  467.        // return;
  468. //    var tree = document.getElementById("Allow");
  469. //    tree.database.AddDataSource(aimRDF().GetDataSource("rdf:AIM"));
  470. //    tree.setAttribute('ref', tree.getAttribute('ref')); 
  471.     var tree = document.getElementById("Deny");
  472.     tree.database.AddDataSource(aimRDF().GetDataSource("rdf:AIM"));
  473.     tree.setAttribute('ref', tree.getAttribute('ref'));
  474.   }
  475.     var priv = aimPrivacy();
  476.   // do it only the first time!
  477.     if (parent.lastPrivacyMode == undefined)
  478.         parent.lastPrivacyMode = priv.PrivacyMode;
  479.  
  480.     lastRadio = modeToRadio(parent.lastPrivacyMode);
  481.   if ( lastRadio != undefined && lastRadio != null)
  482.         lastRadio.setAttribute("selected","true");
  483.   var loggedin = true;
  484.  
  485.     if (loggedin && (parent.lastPrivacyView == undefined))
  486.     {
  487.         aimAdminManager().ExecuteIfReady(adminGetterCallback);
  488.     }
  489.     updateListBoxSelection("Deny");
  490. }
  491.  
  492. function PrefIcqPrivacyOnUnload() 
  493. {
  494.     // nothing for now
  495. }
  496.  
  497. // grab a screenname from the user.
  498.  
  499. function PostGetUserDlg( which )
  500.     openDialog("chrome://aim/content/pref-Icq_getuser.xul", "", 
  501.         "modal=yes,chrome", which);
  502. }
  503.  
  504. function DeleteFromList( which )
  505. {
  506.     var listbox = document.getElementById(which);
  507.     var pIAimPrivacy = aimPrivacy();
  508.     var selectedUser;
  509.     
  510.         
  511.     for (var i = 0; i <= listbox.selectedItems.length; i++) {
  512.       selectedUser = listbox.selectedItems[i].getAttribute("label");
  513.       if ( which == "Allow" ) {
  514.           pIAimPrivacy.AllowListRemove( selectedUser );
  515.           }
  516.       else if ( which == "Deny" ) {
  517.           pIAimPrivacy.DenyListRemove( selectedUser );
  518.           }
  519.       updateListBoxSelection(which);
  520.       break;
  521.     }
  522.  
  523.     var answer = confirm(getString("confirmICQ.AddUser"));
  524.  
  525.     if ( answer == true && which == "Deny") 
  526.     {
  527.         openDialog("chrome://aim/content/BuddyAddBuddy.xul", "", "modal=yes,titlebar,chrome", 
  528.                null, null, selectedUser);
  529.     }
  530.  
  531. }
  532.  
  533. // onload handler for the dialog used to get a screenname from the user
  534.  
  535. function GetUserOnLoad()
  536. {
  537.   doSetOKCancel(GetUserAdd, 0);
  538.     top.addMode = window.arguments[0];
  539.     document.getElementById("fldUserName").focus();
  540. }
  541.  
  542. // called when OK button is pressed in privacy mode preferences panel. Figure
  543. // out what changed, communicate this to AIM Glue backend
  544.  
  545. function AssertPrivacyChanges()
  546. {
  547.     var IMServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  548.     var pIIMManager  = IMServiceClass.getService(Components.interfaces.nsIIMManager)
  549.     var lastRadio = null;
  550.     var allEnums = Components.interfaces.nsAimPrivacyModes;
  551.     var pIAimPrivacy = pIIMManager.QueryInterface(Components.interfaces.nsIAimPrivacy)
  552.     
  553.     if ( pIAimPrivacy == undefined || pIAimPrivacy == null )
  554.         return;
  555.  
  556.     // This has been simplified and made correct
  557.     pIAimPrivacy.PrivacyMode = parent.lastPrivacyMode;
  558.     var tvalues = false;
  559.  
  560.     var pAimAdmin = pIIMManager.QueryInterface(Components.interfaces.nsIAimAdminManager);
  561.     
  562.     if ( pAimAdmin == undefined || pAimAdmin == null )
  563.         return;
  564.  
  565.     adminSetterCallback = new Object();
  566.     adminSetterCallback.ExecuteIfReady = function()
  567.     {
  568.     Components.classes['@netscape.com/aim/IMManager;1'].getService(Components.interfaces.nsIIMManager).QueryInterface(Components.interfaces.nsIAimAdminManager).ChangeRegistrationStatusPreference(null,parent.lastPrivacyView);
  569.     }
  570.  
  571.     pAimAdmin.ExecuteIfReady(adminSetterCallback);
  572.     return;
  573. }
  574.  
  575. function
  576. FindAwayMessageTargetByName( msgName )
  577. {
  578.     GetRDFService();
  579.  
  580.     var messages_file = GetRdfFileUrl("default-messages-icq.rdf", "icqdm.rdf");  
  581.     var datasource = RDF.GetDataSource(messages_file);
  582.   var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  583.   container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  584.   container.Init(datasource, RDF.GetResource("NC:ICQ/AwayMessageBag"));
  585.  
  586.     var elements = container.GetElements();
  587.     var target, node;
  588.     var nameResource = 
  589.                 RDF.GetResource("http://home.netscape.com/NC-rdf#MsgName");
  590.     while ( elements.hasMoreElements() ) {
  591.         node = elements.getNext();
  592.         if ( node ) 
  593.             target = datasource.GetTarget( node, nameResource, 
  594.                 true );
  595.       if ( target ) 
  596.             target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
  597.     if ( target && target.Value == msgName ) 
  598.             return target.Value;
  599.     }
  600.     return null;
  601. }
  602.  
  603. function
  604. EditAwayMessageOnOK()
  605. {
  606.     var nameItem = document.getElementById("awayMessageName");
  607.     var textItem = document.getElementById("awayMessageText");
  608.     var nameValue = null;
  609.     var textValue = null;
  610.  
  611.     if ( !nameItem || nameItem == undefined ) 
  612.         return;
  613.     if ( !textItem || textItem == undefined ) 
  614.         return;
  615.     nameValue = nameItem.value;
  616.     textValue = textItem.value;
  617.     if ( nameValue == "" ) {
  618.         aimErrorBox(aimString("away.EnterLabel"));
  619.         return;
  620.     }
  621.     if ( textValue == "" ) {
  622.         aimErrorBox(aimString("away.EnterMessage"));
  623.         return;
  624.     }
  625.  
  626.     var target = FindAwayMessageTargetByName( nameValue );
  627.     if ( target == null ) {
  628.         retval = confirm(getString("away.DoesNotExist"));
  629.         if ( retval == true ) 
  630.             AssertAwayMessage( nameValue, textValue ); 
  631.         else
  632.             return;
  633.     } else 
  634.         SetAwayMessageTarget( nameValue, textValue )
  635.     top.window.close();
  636. }
  637.  
  638. function
  639. AddAwayMessageOnOK()
  640. {
  641.     var nameItem = document.getElementById("awayMessageName");
  642.     var textItem = document.getElementById("awayMessageText");
  643.     var nameValue = null;
  644.     var textValue = null;
  645.  
  646.     if ( !nameItem || nameItem == undefined ) 
  647.         return;
  648.     if ( !textItem || textItem == undefined ) 
  649.         return;
  650.     nameValue = nameItem.value;
  651.     textValue = textItem.value;
  652.     if ( nameValue == "" ) {
  653.         aimErrorBox(aimString("away.EnterLabel"));
  654.         return;
  655.     }
  656.     if ( textValue == "" ) {
  657.         aimErrorBox(aimString("away.EnterMessage"));
  658.         return;
  659.     }
  660.  
  661.     if ( FindAwayMessageTargetByName( nameValue ) != null ) {
  662.  
  663.         // ask them if they would like to overwrite (i.e., 
  664.         // turn this into an edit).
  665.  
  666.         var response = confirm(getString("away.AlreadyExists"));
  667.         if ( response == true ) {
  668.             EditAwayMessageOnOK();
  669.             return;
  670.         } else {
  671.             aimErrorBox(aimString("away.EnterLabel"));
  672.             return;
  673.         }
  674.     }
  675.  
  676.     AssertAwayMessage( nameValue, textValue ); 
  677.     top.window.close();
  678. }
  679.  
  680. function
  681. AssertAwayMessage( nameValue, textValue )
  682. {
  683.     GetRDFService();
  684.  
  685.     var newmsg = RDF.GetAnonymousResource();
  686.     var messages_file = GetRdfFileUrl("default-messages-icq.rdf", "icqdm.rdf");  
  687.  
  688.     var datasource = 
  689.         RDF.GetDataSource(messages_file);
  690.     datasource.Assert(newmsg, 
  691.         RDF.GetResource("http://home.netscape.com/NC-rdf#MsgName"),
  692.             RDF.GetLiteral(nameValue), true);
  693.     datasource.Assert(newmsg, 
  694.         RDF.GetResource("http://home.netscape.com/NC-rdf#MsgText"),
  695.         RDF.GetLiteral(textValue), true);
  696.  
  697.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  698.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  699.       container.Init(datasource, RDF.GetResource("NC:ICQ/AwayMessageBag"));
  700.  
  701.     container.AppendElement(newmsg);
  702.     datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  703. }
  704.  
  705. function
  706. AddAwayMessage()
  707. {
  708. // title is window.arguments[1];
  709. // content is window.arguments[2];
  710.  
  711.      window.openDialog("chrome://aim/content/AddIcqAwayMessage.xul","_blank", "chrome,close,titlebar,modal", "", "", "");
  712. }
  713.  
  714. function
  715. EditAwayMessage()
  716. {
  717. // title is window.arguments[1];
  718. // content is window.arguments[2];
  719.  
  720.     var msgName, msgText;
  721.     var response;
  722.  
  723.     response = FindSelectedAwayMessage();
  724.     if ( response == null ) {
  725.         aimErrorBox(aimString("away.PleaseSelectToEdit"));
  726.         return;
  727.     } else {
  728.         msgName = response.msgName;
  729.         msgText = response.msgText;
  730.     }
  731.  
  732.      window.openDialog("chrome://aim/content/AddIcqAwayMessage.xul","_blank", "chrome,close,titlebar, modal", "", msgName, msgText);
  733. }
  734.  
  735. function
  736. RemoveAwayMessage()
  737. {
  738.     var msgName, msgText;
  739.     var response;
  740.  
  741.     response = FindSelectedAwayMessage();
  742.     if ( response == null ) {
  743.         aimErrorBox(aimString("away.PleaseSelectToRemove"));
  744.         return;
  745.     } 
  746.  
  747.     answer = confirm(getString("away.AreYouSure").replace(/%AwayMsg%/,response.msgName));
  748.     if ( answer == true ) 
  749.         RemoveTarget( response.msgName );
  750. }
  751.  
  752. function
  753. FindSelectedAwayMessage()
  754. {
  755.         var selection;
  756.     var tree = document.getElementById("AwayMessages");
  757.  
  758.     var response = new Object();
  759.  
  760.         if ( tree )
  761.                 selection = tree.contentView.getItemAtIndex(tree.currentIndex);
  762.  
  763.         if ( selection) {
  764.             response.msgName = selection.getAttribute("MsgName");
  765.         response.msgText = selection.getAttribute("MsgText");
  766.  
  767.         return response;
  768.     }
  769.     return null;
  770. }
  771.  
  772.  
  773. function getCurrentIcqNumber()
  774.  {
  775.    var myaimSession = aimSession();
  776.    if (myaimSession) {
  777.      return myaimSession.CurrentScreenName;
  778.    }
  779.    else
  780.      return "";
  781.  }
  782.  
  783.  //XXXVISHY - per screen name stuff
  784.   
  785. function getCurrentScreenName()
  786. {
  787.   var myaimSession = aimSession();
  788.   if (myaimSession) {
  789.     return myaimSession.CurrentScreenName;
  790.   }
  791.   else
  792.     return "";
  793. }
  794.  
  795.  
  796. // XXXVISHY - the icqPreferenceOnload function MUST be called in the
  797. // onload handler of every icq preference panel so as to do the
  798. // per screen name munging
  799.  
  800. /* every element has: prefstring, preftype, preattribute, pref (true/false), prefscope(0,1,2)
  801.  
  802. preftype, a type of value to retrieve;
  803. preattribute, a type of element attribute to assign
  804.  
  805.  
  806. preftype = true, if it is for preference element only
  807. prefscope = 0, PER_SN,
  808. prefscope = 2, SESSION_GLOBAL,
  809. prefscope = 1, GEN_GLOBAL
  810.  
  811. */
  812.  
  813. function icqPreferenceOnload()
  814. {
  815. dump("starting icqPreferenceOnload\n");     
  816.     var aimprefs = document.getElementsByAttribute("pref", "true");
  817.     var sN;
  818.     var qPreference;
  819.     var curDefPref;
  820.     var panelType = 2;
  821.      
  822.     for (var i = 0 ; i < aimprefs.length ; i++) {
  823.          var preference = aimprefs[i].getAttribute("prefstring");
  824.         var curprefScope = aimprefs[i].getAttribute("prefscope");
  825. dump("curprefScope=" + curprefScope + "\n");        
  826.         if (curprefScope == 2 || curprefScope == 1) {
  827.         
  828.             if (panelType == 0)
  829.                 qPreference = preference + ".aim";
  830.             else //panelType == 2
  831.                 qPreference = preference + ".icq";
  832.                         
  833.         }
  834.         else { // scope == 0, PER_SN
  835.  
  836.           if (panelType == aimPrefsManager().GetSessionType()) 
  837.           {
  838.             sN = getCurrentScreenName() + "."; 
  839.             qPreference = sN + preference;
  840.  
  841.             if (MozPreferences.getPrefType(qPreference) == Components.interfaces.nsIPrefBranch.PREF_INVALID)
  842.             {
  843.             // first time with this pref, so create a per screen name copy
  844.                 if (MozPreferences.getPrefType(preference) == Components.interfaces.nsIPrefBranch.PREF_INVALID)
  845.                  {
  846.                 // "preference" is not default name, create default name
  847.                     
  848.                     if (panelType == 0)
  849.                         curDefPref = preference + ".aim";
  850.                     else //panelType == 2
  851.                         curDefPref = preference + ".icq";
  852.                 }
  853.                 else {
  854.                     curDefPref = preference;
  855.                 }
  856. dump("curDefPref=" + curDefPref + "\n");
  857.  
  858.                 switch (MozPreferences.getPrefType(curDefPref)) {
  859.                 case Components.interfaces.nsIPrefBranch.PREF_STRING:
  860.                 var sPref = MozPreferences.getCharPref(curDefPref);        
  861.                 MozPreferences.setCharPref(qPreference, sPref);
  862.                 break;
  863.                 case Components.interfaces.nsIPrefBranch.PREF_INT:
  864.                 var iPref = MozPreferences.getIntPref(curDefPref);
  865.                 MozPreferences.setIntPref(qPreference, iPref);
  866.                 break;
  867.                 case Components.interfaces.nsIPrefBranch.PREF_BOOL:
  868.                 var bPref = MozPreferences.getBoolPref(curDefPref);
  869.                 MozPreferences.setBoolPref(qPreference, bPref);
  870.                 break;
  871.                 default:
  872.                 dump("Bad pref type for NIM\n");
  873.                 break;
  874.                 }
  875.  
  876.  
  877.             }
  878.  
  879.             
  880.           }                  
  881.         else
  882.           {
  883.             qPreference = "__000." + preference;
  884.           
  885.           }
  886.         }
  887.  
  888. dump("qPreference=" + qPreference + "\n");    
  889.         aimprefs[i].setAttribute("prefstring", qPreference);
  890.     
  891.      }
  892.  
  893. }
  894.  
  895.  
  896.  
  897. function DisableIcqAwayUI()
  898. {
  899.         var el = document.getElementById("buttonAddMess");
  900.         if ( el )
  901.             el.setAttribute( "disabled", "true" );
  902.         el = document.getElementById("buttonEditMess");
  903.         if ( el )
  904.             el.setAttribute( "disabled", "true" );
  905.         el = document.getElementById("buttonRemoveMess");
  906.         if ( el )
  907.             el.setAttribute( "disabled", "true" );
  908.         el = document.getElementById("AwayMessages");
  909.         if ( el )
  910.             el.setAttribute( "disabled", "true" );
  911.         
  912. }
  913.  
  914.  
  915. function DiscardAwayChanges()
  916. {
  917.   aimErrorBox(aimString("icqaway.exitmsg"));
  918. }
  919.  
  920.  
  921. function changeContactListDisplay()
  922. {
  923. // Nothing for now
  924. }
  925.  
  926. /************* Related to the Connection/Proxy Panel ********************/
  927.  
  928.  
  929.  
  930. /*Below all new function for connection panel*/
  931.  
  932. //OnLoad addconnection.xul
  933. function EditConnectionOnLoad()
  934. {
  935.     // window.arguments[1] is type of ops for title,
  936.     // window.arguments[2] is connection name
  937.  
  938.  
  939.     var panelTtl = document.getElementById("panelTitle");
  940.  
  941.     var connectName = document.getElementById("connectName");
  942.  
  943. dump("arg1=" + window.arguments[1] + "\narg2=" + window.arguments[2] + "\n");
  944.     if (window.arguments[1] == "Add") {          
  945.         panelTtl.setAttribute('title' , panelTtl.getAttribute('titl1'));
  946.  
  947.  
  948.         doSetOKCancel(AddConnMessageOnOK, 0);
  949.  
  950.         connLinks.ConnectionName = "";
  951.         connLinks.SessionType    = 2;
  952.         connLinks.Host           = "";
  953.         connLinks.Port           = "";
  954.         connLinks.ProxyHost      = "";
  955.         connLinks.ProxyPort      = 1080;
  956.         connLinks.ProxyUser      = "";
  957.         connLinks.ProxyPassword  = "";
  958.         connLinks.ProxyProtocol  = 0;
  959.         connLinks.IsProxy        = false;
  960.         connLinks.ConnectionType = 2;
  961.         
  962.     }
  963.     else { /* Edit mode */
  964.         panelTtl.setAttribute('title' , panelTtl.getAttribute('titl2'));
  965.         
  966.  
  967.         doSetOKCancel(EditConnMessageOnOK, 0);
  968.         
  969.         var curConnName = window.arguments[2];
  970.  
  971.         setValuesFromRDF (curConnName);
  972.  
  973.     }
  974.         
  975.     setConnUI();
  976.     
  977.     DoFullEnabling();
  978.     
  979. }
  980.  
  981. function setValuesFromRDF (connectionName)
  982. {
  983. dump("starting setValuesFromRDF\n");    
  984.     GetRDFService();
  985.  
  986.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  987.     var datasource = RDF.GetDataSource(messages_file);
  988.         
  989.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  990.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  991.       container.Init(datasource, RDF.GetResource("NC:AIM/ConnectionsSeq"));
  992.  
  993.     var ConnNameLiteral = RDF.GetLiteral(connectionName);
  994.  
  995.     var ConnName = RDF.GetResource("http://home.netscape.com/NC-rdf#ConnectionName");
  996.  
  997.     var node = datasource.GetSource (ConnName, ConnNameLiteral, true);
  998.  
  999.     if (node)
  1000.     {
  1001.         var curName;
  1002.         for (var linkName in connLinks)
  1003.         {
  1004.             curName = datasource.GetTarget (node, 
  1005.                                             RDF.GetResource("http://home.netscape.com/NC-rdf#" + linkName),
  1006.                                             true);
  1007.             if ( curName ) {
  1008.                 curName = curName.QueryInterface(Components.interfaces.nsIRDFLiteral);
  1009.                 connLinks[linkName] = curName.Value;
  1010.             }
  1011.         }
  1012.     }
  1013.  
  1014. }
  1015.  
  1016. function DoFullEnabling() {
  1017.  
  1018.     var connectName = document.getElementById("connectName");
  1019.     var aimHost = document.getElementById("aimHost");
  1020.     var aimPort = document.getElementById("aimPort");
  1021.  
  1022.     var Name = connectName.value;
  1023.  
  1024.     if (Name == "AIM" || Name == "AOL" || Name == "ICQ") {
  1025.         connectName.setAttribute( "disabled", "true" );
  1026.         aimHost.setAttribute( "disabled", "true" );
  1027.     }
  1028.     else {
  1029.         if (window.arguments[1] == "Add") {
  1030.             connectName.setAttribute( "disabled", "false" );
  1031.             connectName.removeAttribute( "disabled" );
  1032.         }
  1033.         else { // Edit
  1034.             connectName.setAttribute( "disabled", "true" );        
  1035.         }
  1036.  
  1037.         aimHost.setAttribute( "disabled", "false" );
  1038.         aimHost.removeAttribute( "disabled" );
  1039.  
  1040.     }
  1041.  
  1042.     // enable proxy protocol fields
  1043.     DoEnabling();
  1044. }
  1045.  
  1046. //OnLoad pref-IM_connection.xul
  1047. function PrefIMConnectionOnLoad(){
  1048.     // init datasource
  1049. dump("starting PrefIMConnectionOnLoad\n");
  1050.  
  1051.     GetRDFService();
  1052.  
  1053.     // copy file to profile  and return full URL of the file
  1054.     var connection_file = CopynGetUrl("default-connections.rdf", "connections.rdf");
  1055.  
  1056.     if (!connection_file)
  1057.         return;
  1058.  
  1059.     datasource = RDF.GetDataSource(connection_file);
  1060.  
  1061.     dump( "datasource " + datasource + "\n" );
  1062.  
  1063.     var tree = document.getElementById("ConnectionList");
  1064.     tree.database.AddDataSource(datasource);
  1065.     tree.setAttribute('ref', tree.getAttribute('ref'));
  1066.  
  1067.     // disable 2 buttons, no selection here
  1068.     document.getElementById("btnEdit").setAttribute("disabled", true);
  1069.     document.getElementById("btnRemove").setAttribute("disabled", true);
  1070. }
  1071.  
  1072.  
  1073. function FindSelectedConnection(connInfo)
  1074. {
  1075.     var selection;
  1076.     var list = document.getElementById("ConnectionList");
  1077. dump("starting FindSelectedConnection\n");
  1078.  
  1079.  
  1080.     if ( list && list.selectedItem ) {
  1081.              connInfo.name          = list.selectedItem.getAttribute("ConnectionName");
  1082.              connInfo.sessiontype   = list.selectedItem.getAttribute("sessionType");
  1083. dump("connInfo.name=" + connInfo.name + " connInfo.sessiontype=" + connInfo.sessiontype + "\n");
  1084.             return connInfo;
  1085.         
  1086.     }
  1087.     return null;
  1088. }
  1089.  
  1090.  
  1091. // 3 buttons
  1092. function AddConnMessage()
  1093. {
  1094. dump("starting AddConnMessage\n");
  1095.  
  1096.     window.openDialog("chrome://aim/content/pref-Icq_addconnection.xul","_blank", "chrome,close,titlebar,modal", "", "Add", "");
  1097.     
  1098. }
  1099.  
  1100. function EditConnMessage()
  1101. {
  1102. dump("starting EditConnMessage\n");
  1103.  
  1104.     var ConnectionInfo = new Object();
  1105.     ConnectionInfo.name ="";
  1106.     ConnectionInfo.sessiontype = "";
  1107.  
  1108.  
  1109.     FindSelectedConnection(ConnectionInfo);
  1110.     var ConnectionName = ConnectionInfo.name;
  1111.  
  1112. dump("ConnectionName=" + ConnectionName + "\n");
  1113.     if ( ConnectionName == null ) {
  1114.         alert(getString("connection.PleaseSelectToEdit"));
  1115.         return;
  1116.     }     
  1117.  
  1118.     window.openDialog("chrome://aim/content/pref-Icq_addconnection.xul","_blank", "chrome,close,titlebar, modal", "", "Edit", ConnectionName);
  1119.  
  1120. }
  1121.  
  1122. function RemoveConnMessage()
  1123. {
  1124. dump("starting RemoveConnMessage\n");
  1125.  
  1126.     var ConnectionInfo = new Object();
  1127.     ConnectionInfo.name ="";
  1128.     ConnectionInfo.sessiontype = "";
  1129.  
  1130.  
  1131.     FindSelectedConnection(ConnectionInfo);
  1132.     var ConnectionName = ConnectionInfo.name;
  1133.  
  1134.     if ( ConnectionName == null ) {
  1135.         alert(getString("connection.PleaseSelectToRemove"));
  1136.         return;
  1137.     }
  1138.  
  1139.     var answer = confirm(getString("connection.AreYouSure").replace(/%AwayMsg%/, ConnectionName));
  1140.  
  1141.     if ( answer == true ) 
  1142.         RemoveConnectionfromDatasrc( ConnectionName );
  1143.  
  1144.  
  1145. }
  1146.  
  1147.  
  1148. function RemoveConnectionfromDatasrc( ConnectionName )
  1149. {
  1150.     GetRDFService();
  1151.  
  1152.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1153.     var datasource = RDF.GetDataSource(messages_file);
  1154.         
  1155.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  1156.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  1157.       container.Init(datasource, RDF.GetResource("NC:AIM/ConnectionsSeq"));
  1158.  
  1159.     var ConnNameLiteral = RDF.GetLiteral(ConnectionName);
  1160.  
  1161.     var ConnName = RDF.GetResource("http://home.netscape.com/NC-rdf#ConnectionName");
  1162.  
  1163.     var node = datasource.GetSource (ConnName, ConnNameLiteral, true);
  1164.  
  1165.     if (node) {
  1166.         // remove from container
  1167.         container.RemoveElement( node, true );
  1168.  
  1169.         // remove connection info
  1170.         var curProp;
  1171.         var curTarget;
  1172.         for (var curName in connLinks)
  1173.         {
  1174.           curProp   = RDF.GetResource("http://home.netscape.com/NC-rdf#" + curName);
  1175.           curTarget = datasource.GetTarget(node, curProp, true);
  1176.             
  1177.           datasource.Unassert (node, curProp, curTarget );
  1178.         }        
  1179.  
  1180.         datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  1181.     }
  1182.  
  1183.     return null;
  1184.  
  1185. }
  1186.  
  1187.  
  1188. //2 callbacks for AddConnection editing window
  1189. function AddConnMessageOnOK()
  1190. {
  1191.     dump("starting AddConnMessageOnOK\n");
  1192.     GetRDFService();
  1193.  
  1194.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1195.     var datasource = RDF.GetDataSource(messages_file);
  1196.  
  1197.     var connectName = document.getElementById("connectName");
  1198.     var connectNameVal = connectName.value;
  1199.  
  1200. dump("connectNameVal=" + connectNameVal + "\n");
  1201.     if (connectNameVal == "")
  1202.     {
  1203.         alert(getString("connection.EnterName"));
  1204.         return;
  1205.     }
  1206.  
  1207.     var node = datasource.GetSource (RDF.GetResource("http://home.netscape.com/NC-rdf#ConnectionName"), 
  1208.                                      RDF.GetLiteral(connectNameVal), 
  1209.                                      true);
  1210.  
  1211.     if (node) {
  1212.         alert(getString("connection.AlreadyExists"));
  1213.         return;
  1214.     }
  1215.     
  1216.  
  1217.     getConnInfoFromUI();
  1218.  
  1219.     AddConnectionDatasource ();
  1220.     top.window.close();
  1221. }
  1222.  
  1223. function EditConnMessageOnOK()
  1224. {
  1225.     GetRDFService();
  1226.  
  1227.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1228.     var datasource = RDF.GetDataSource(messages_file);
  1229.  
  1230.     var connectNameVal = document.getElementById("connectName").value;
  1231.  
  1232.     var node = datasource.GetSource (RDF.GetResource("http://home.netscape.com/NC-rdf#ConnectionName"), 
  1233.                                      RDF.GetLiteral(connectNameVal), 
  1234.                                      true);
  1235.  
  1236.     if (!node)
  1237.         return;
  1238.  
  1239.     getConnInfoFromUI();
  1240.  
  1241.     EditConnectionDatasource(node);
  1242.     top.window.close();
  1243. }
  1244.  
  1245. function setConnUI()
  1246. {
  1247.  
  1248.     var panelSessionType = 2;
  1249.  
  1250.     var connectName = document.getElementById("connectName");
  1251.     var aimHost = document.getElementById("aimHost");
  1252.     var aimPort = document.getElementById("aimPort");
  1253.     var proxyHost = document.getElementById("proxyHost");
  1254.     var proxyPort = document.getElementById("proxyPort");
  1255.     var proxyUserName = document.getElementById("proxyUserName");
  1256.     var proxyPassword = document.getElementById("proxyPassword");
  1257.     var proxyUse = document.getElementById("proxyUse");
  1258.     var proxyProtocol = document.getElementById("proxyProtocol");
  1259.  
  1260.     if (panelSessionType != 2)
  1261.        var IsAol = document.getElementById("IsAol");
  1262.  
  1263.     connectName.value = connLinks.ConnectionName;
  1264.  
  1265.     aimHost.value = connLinks.Host;    
  1266.     aimPort.value = connLinks.Port;    
  1267.     proxyHost.value = connLinks.ProxyHost;    
  1268.     proxyPort.value = connLinks.ProxyPort;    
  1269.     proxyUserName.value = connLinks.ProxyUser;    
  1270.  
  1271.     var pIAimSession = aimSession();
  1272.        if ( pIAimSession ) {
  1273.            proxyPassword.value = pIAimSession.UnMungeString(connLinks.ProxyPassword);
  1274. dump("UnMungeString connLinks.ProxyPassword=" + connLinks.ProxyPassword + " proxyPassword.value=" + proxyPassword.value + "\n");
  1275.        }
  1276.  
  1277.     
  1278.     if (connLinks.ProxyProtocol > 0 && connLinks.ProxyProtocol <= 4)
  1279.         proxyProtocol.selectedItem = proxyProtocol.childNodes[connLinks.ProxyProtocol - 1];
  1280.     else
  1281.         proxyProtocol.selectedItem = proxyProtocol.childNodes[0];
  1282.  
  1283.  
  1284.     if (connLinks.IsProxy == "true")
  1285.       proxyUse.setAttribute ("checked", true);
  1286.     else
  1287.       proxyUse.setAttribute ("checked", false);
  1288.  
  1289. dump("proxyUse.checked=" + proxyUse.checked + "  connLinks.IsProxy=" + connLinks.IsProxy + "\n");
  1290.  
  1291.     if (panelSessionType != 2) {
  1292.         if (connLinks.ConnectionType == 1)
  1293.             proxyUse.setAttribute ("checked", true);
  1294.         else
  1295.             proxyUse.setAttribute ("checked", false);
  1296.         
  1297.     }
  1298.  
  1299. }
  1300.  
  1301. // Remove whitespace from both ends of a string
  1302. function TrimString(string)
  1303. {
  1304.   if (!string) return "";
  1305.   return string.replace(/(^\s+)|(\s+$)/g, '')
  1306. }
  1307.  
  1308. function getConnInfoFromUI()
  1309. {
  1310.     var panelSessionType = 2;
  1311.  
  1312.     var connectName = document.getElementById("connectName");
  1313.     var aimHost = document.getElementById("aimHost");
  1314.     var aimPort = document.getElementById("aimPort");
  1315.     var proxyHost = document.getElementById("proxyHost");
  1316.     var proxyPort = document.getElementById("proxyPort");
  1317.     var proxyUserName = document.getElementById("proxyUserName");
  1318.     var proxyPassword = document.getElementById("proxyPassword");
  1319.     var proxyUse = document.getElementById("proxyUse");
  1320.     var proxyProtocol = document.getElementById("proxyProtocol");
  1321.     var IsAol = document.getElementById("IsAol");
  1322.  
  1323.     connLinks.ConnectionName =  TrimString(connectName.value);
  1324.     connLinks.SessionType    =  panelSessionType;
  1325. dump("getConnInfoFromUI connLinks.SessionType=" + connLinks.SessionType + "\n");
  1326.     connLinks.Host           =  TrimString(aimHost.value);    
  1327.     connLinks.Port           =  TrimString(aimPort.value);    
  1328.     connLinks.ProxyHost      =  TrimString(proxyHost.value);    
  1329.     connLinks.ProxyPort      =  TrimString(proxyPort.value);    
  1330.     connLinks.ProxyUser      =  TrimString(proxyUserName.value);
  1331.  
  1332.     var pIAimSession = aimSession();
  1333.     if(pIAimSession) {
  1334.         // trim?
  1335.            connLinks.ProxyPassword = pIAimSession.MungeString(proxyPassword.value);
  1336. dump("MungeString proxyPassword.value=" + proxyPassword.value + " connLinks.ProxyPassword=" + connLinks.ProxyPassword + "\n");
  1337.  
  1338.     }
  1339.     
  1340.     // trim?
  1341.                 
  1342.     connLinks.ProxyProtocol  =  proxyProtocol.selectedItem.getAttribute("value");
  1343.     connLinks.IsProxy        =  proxyUse.checked;
  1344.  
  1345. dump("panelSessionType=" + panelSessionType + "\n");
  1346.     if (panelSessionType != 2) {
  1347.         if (IsAol.checked)
  1348.             connLinks.ConnectionType = 1;
  1349.         else
  1350.             connLinks.ConnectionType = 0;
  1351.         
  1352.     }
  1353.     else
  1354.         connLinks.ConnectionType = 2;
  1355. }
  1356.  
  1357. function AddConnectionDatasource()
  1358. {
  1359.     GetRDFService();
  1360.  
  1361.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1362.     var datasource = RDF.GetDataSource(messages_file);
  1363.  
  1364.     var newConn = RDF.GetAnonymousResource();
  1365.  
  1366.     for (var curName in connLinks)     
  1367.     {
  1368.         datasource.Assert(newConn, RDF.GetResource("http://home.netscape.com/NC-rdf#" + curName),        
  1369.                 RDF.GetLiteral(connLinks[curName]), true);
  1370.     }
  1371.  
  1372.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  1373.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  1374.       container.Init(datasource, RDF.GetResource("NC:AIM/ConnectionsSeq"));
  1375.  
  1376.     container.AppendElement(newConn);
  1377.     datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  1378.  
  1379. }
  1380.  
  1381.  
  1382. function EditConnectionDatasource( connectionNode )
  1383. {
  1384.     GetRDFService();
  1385.  
  1386.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1387.     var datasource = RDF.GetDataSource(messages_file);
  1388.  
  1389.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  1390.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  1391.       container.Init(datasource, RDF.GetResource("NC:AIM/ConnectionsSeq"));
  1392.  
  1393.     var curLinkRes;
  1394.     var oldTarget;
  1395.     for(var curName in connLinks) 
  1396.     {
  1397.         if (curName != "ConnectionName") {// ConnectionName was set already
  1398.             curLinkRes = RDF.GetResource("http://home.netscape.com/NC-rdf#" + curName);
  1399.             oldTarget  = datasource.GetTarget(connectionNode, curLinkRes, true);
  1400.                                                                                           
  1401.             datasource.Change( connectionNode, curLinkRes,                               
  1402.                                oldTarget, RDF.GetLiteral(connLinks[curName]) );                               
  1403.         }
  1404.     }
  1405.  
  1406.         
  1407.     datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  1408.  
  1409. }
  1410. /* keep it for the future for external session UI */
  1411. /*
  1412. function SetExternalConnection()
  1413. {
  1414.     var ConnectionInfo = new Object();
  1415.     ConnectionInfo.name ="";
  1416.     ConnectionInfo.sessiontype = "";
  1417.  
  1418.  
  1419.     FindSelectedConnection(ConnectionInfo);
  1420.     var ConnectionName = ConnectionInfo.name;
  1421.  
  1422.     document.getElementById("mailConn").value = ConnectionName;
  1423.     setConnectionInfo (ConnectionName, "mail");
  1424.  
  1425. }
  1426. */
  1427.  
  1428. function SetHostPortDefault(type)
  1429. {
  1430.  
  1431. dump("type=" + type + "\n");
  1432.     var host = document.getElementById("aimHost"); 
  1433.     var port = document.getElementById("aimPort");
  1434.  
  1435.         host.setAttribute("value", "login.icq.com");
  1436.         port.setAttribute("value", "5190");        
  1437.  
  1438.  
  1439. }
  1440.  
  1441. function EnableConnButtons()
  1442. {
  1443.     var connInfo = new Object();
  1444.     connInfo.name ="";
  1445.     connInfo.sessiontype = "";
  1446.  
  1447.  
  1448.     FindSelectedConnection(connInfo);
  1449.     var ConnectionName = connInfo.name;
  1450.  
  1451.     var panelSessionType = 2;
  1452. dump("connInfo.name =" + connInfo.name + " connInfo.sessiontype=" + connInfo.sessiontype + 
  1453.      "panelSessionType=" + panelSessionType + "\n");
  1454.  
  1455.     if(connInfo.sessiontype == panelSessionType) {
  1456.         document.getElementById("btnEdit").setAttribute("disabled", false);
  1457.         document.getElementById("btnEdit").removeAttribute( "disabled" );    
  1458.        
  1459.     }
  1460.     else {
  1461.         document.getElementById("btnEdit").setAttribute("disabled", true);    
  1462.     }
  1463.  
  1464.  
  1465.     if (connInfo.name == "AIM" || connInfo.name == "AOL" || connInfo.name == "ICQ" ||
  1466.         (connInfo.sessiontype != panelSessionType)) {
  1467.     
  1468.         document.getElementById("btnRemove").setAttribute("disabled", true);
  1469.     
  1470.     }
  1471.     else {
  1472.         document.getElementById("btnRemove").setAttribute("disabled", false);
  1473.         document.getElementById("btnRemove").removeAttribute( "disabled" ); 
  1474.     }
  1475.  
  1476.  
  1477. }
  1478.  
  1479. // new update
  1480.  
  1481. function PrefIMConnectionOnload()
  1482. {
  1483.    var proxPass = "";
  1484.    DoEnabling();
  1485.    parent.ConnectionLoadicq = 1;
  1486.    parent.connectionSavedicq = 0;
  1487.    if ( parent.ConnectionCallbackicq == undefined || 
  1488.         parent.ConnectionCallbackicq == null ) {
  1489.  
  1490.     // Register the OK callback func once, and unmunge the initial value 
  1491.  
  1492.     parent.ConnectionCallbackicq = 1;
  1493.        parent.hPrefWindow.registerOKCallbackFunc( AssertProxyChangesIcq );
  1494.        var pIAimSession = aimSession();
  1495.        if ( pIAimSession ) {
  1496.            proxPass = pIAimSession.UnMungeString(document.getElementById("proxyPasswordicq").value);
  1497.         parent.proxyPasswordicq = proxPass;
  1498.        }
  1499.    } else {
  1500.  
  1501.     // we switched back from some other panel, so restore the 
  1502.     // saved off value from the unload handler
  1503.  
  1504.     proxPass = parent.proxyPasswordicq;    
  1505.    }
  1506.    document.getElementById("proxyPasswordicq").value = proxPass;
  1507. }
  1508.  
  1509. function
  1510. AssertProxyChangesIcq()
  1511. {
  1512.     // if the connection panel is loaded, base64 the current password
  1513.  
  1514.     if ( parent.ConnectionLoadicq == 1 )
  1515.         MungeProxyPassword();
  1516.  
  1517.     // set this so the unload handler doesn't do anything when called
  1518.  
  1519.     parent.connectionSavedicq = 1;
  1520. }
  1521.  
  1522. function PrefIMConnectionOnunload()
  1523. {
  1524.     // we already saved (e.g., here because OK was hit), so juswt return
  1525.  
  1526.     if ( parent.connectionSavedicq == 1 )
  1527.         return;
  1528.  
  1529.     // ok, switching to some other panel. Save off the current value
  1530.     // to be restored in the onload handler, and remember we are not
  1531.     // visible so we deal with the AssertProxyChanges() callback in
  1532.     // the correct manner
  1533.  
  1534.     parent.proxyPasswordicq = document.getElementById("proxyPasswordicq").value;
  1535.     MungeProxyPassword();        // just in case OK is hit while away
  1536.     parent.ConnectionLoadicq = 0;    
  1537. }
  1538.  
  1539. function DoEnabling()
  1540. {
  1541.   var host = document.getElementById("proxyHosticq");
  1542.   var port = document.getElementById("proxyPorticq");
  1543.   var protocol = document.getElementById("proxyProtocolicq");
  1544.   var userName = document.getElementById("proxyUserNameicq");
  1545.   var password = document.getElementById("proxyPasswordicq");
  1546.   var radiogroup0 = document.getElementById("proxyProtocolSocks4icq");
  1547.   var radiogroup1 = document.getElementById("proxyProtocolSocks5icq");
  1548.   var radiogroup2 = document.getElementById("proxyProtocolHttpsicq");
  1549.   var radiogroup3 = document.getElementById("proxyProtocolHttpicq");
  1550.  
  1551.   // convenience arrays
  1552.   var manual = [host, port, protocol, userName, password, radiogroup0, radiogroup1, radiogroup2, radiogroup3];
  1553.   
  1554.   // checkbox button
  1555.   var checkboxitem = document.getElementById("proxyUseicq");
  1556.   if ( checkboxitem.checked ) {
  1557.       for( var i = 0; i < manual.length; i++ ) {
  1558.         manual[i].setAttribute( "disabled", "false" );
  1559.         manual[i].removeAttribute( "disabled" );
  1560.       }
  1561.   } else {
  1562.       for( var i = 0; i < manual.length; i++ ) 
  1563.         manual[i].setAttribute( "disabled", "true" );
  1564.   }
  1565. }
  1566.  
  1567.  
  1568. function MungeProxyPassword()
  1569. {
  1570.     //XXXVISHY - you cannot use macros like AimSessionObject in
  1571.         // any callback because the javascript context will not remember
  1572.         // the included files!!!
  1573.  
  1574.         var IMServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  1575.         var pIIMManager  = IMServiceClass.getService(Components.interfaces.nsIIMManager)
  1576.         var pIAimSession = pIIMManager.QueryInterface(Components.interfaces.nsIAimSession)
  1577.         var proxPass = "";
  1578.         if(pIAimSession) {
  1579.                proxPass = pIAimSession.MungeString(document.getElementById("proxyPasswordicq").value);
  1580.               document.getElementById("proxyPasswordicq").value = proxPass;
  1581.         }
  1582. }
  1583.  
  1584.  
  1585. function resetConnection()
  1586. {
  1587. dump("Icq reset\n");
  1588.     document.getElementById("aimHosticq").value = "login.icq.com"
  1589.     document.getElementById("aimPorticq").value = "5190";
  1590. }
  1591.  
  1592.  
  1593. /*connection panel end*/
  1594.